package ca.uwindsor.cs.deepweb.estimation.experiment.common;

import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

/**
 * @author Liang Jie
 * 
 */
public class QueryResultXMLSAXHandler extends DefaultHandler {
	private StringBuffer buf;
	private String str;

	protected String ORmethodResultCSV;
	protected String doccapturefrequencydistCSV;
	protected String sizedistributionCSV;
	protected String docfrequencyCSV;
	protected String docsizeCSV;
	protected String docuniquetermsCSV;
	protected String termweightanddocCSV;
	protected String termweightdistCSV;
	protected String docweightCSV;

	/**
	 * 
	 */
	public QueryResultXMLSAXHandler() {
		super();
	}

	public void startDocument() throws SAXException {
		buf = new StringBuffer();
	}

	public void endElement(String namespaceURI, String localName,
			String fullName) throws SAXException {
		str = buf.toString();
		if (fullName.equals("ORmethodresult")) {
			ORmethodResultCSV = str.trim();
		} else if (fullName.equals("capturefrequencydistribution")) {
			doccapturefrequencydistCSV = str.trim();
		} else if (fullName.equals("sizedistribution")) {
			sizedistributionCSV = str.trim();
		} else if (fullName.equals("documentfrequency")) {
			docfrequencyCSV = str.trim();
		} else if (fullName.equals("documentsize")) {
			docsizeCSV = str.trim();
		} else if (fullName.equals("documentuniqueandtotalterms")) {
			docuniquetermsCSV = str.trim();
		} else if (fullName.equals("termweightandnumofdocs")) {
			termweightanddocCSV = str.trim();
		} else if (fullName.equals("termweightfrequencydist")) {
			termweightdistCSV = str.trim();
		} else if (fullName.equals("documentweight")) {
			docweightCSV = str.trim();
		}
		buf.delete(0, buf.length());
	}

	public void characters(char[] chars, int start, int length)
			throws SAXException {
		buf.append(chars, start, length);
	}

	/**
	 * @return the oRmethodResultCSV
	 */
	public String getORmethodResultCSV() {
		return ORmethodResultCSV;
	}

	/**
	 * @return the doccapturefrequencydistCSV
	 */
	public String getDoccapturefrequencydistCSV() {
		return doccapturefrequencydistCSV;
	}

	/**
	 * @return the sizedistributionCSV
	 */
	public String getSizedistributionCSV() {
		return sizedistributionCSV;
	}

	/**
	 * @return the docfrequencyCSV
	 */
	public String getDocfrequencyCSV() {
		return docfrequencyCSV;
	}

	/**
	 * @return the docsizeCSV
	 */
	public String getDocsizeCSV() {
		return docsizeCSV;
	}

	/**
	 * @return the docuniquetermsCSV
	 */
	public String getDocuniquetermsCSV() {
		return docuniquetermsCSV;
	}

	/**
	 * @return the termweightanddocCSV
	 */
	public String getTermweightanddocCSV() {
		return termweightanddocCSV;
	}

	/**
	 * @return the termweightdistCSV
	 */
	public String getTermweightdistCSV() {
		return termweightdistCSV;
	}

	/**
	 * @return the docweightCSV
	 */
	public String getDocweightCSV() {
		return docweightCSV;
	}
}
